<template>
  <div id="app">
    <Topbar :key="topbarkey"> </Topbar>
    <Header> </Header>
    <router-view @updateTopbarkey="updateTopbarkeyFn" />
    <Footer> </Footer>
    <Login v-show="isShowLoginModal"></Login>
    <transition name="slide">
      <Toast v-show="isShowToast"></Toast>
    </transition>
  </div>
</template>
<script>
import Footer from "@/components/Footer.vue";
import Header from "@/components/Header.vue";
import Topbar from "./components/Topbar.vue";
import Login from "@/components/Login.vue";
import Toast from "@/components/Toast.vue";
// import instance from "./request/request.js";
import { JingPinAPI, ReMenAPI } from "./request/api.js";
import { mapState } from "vuex";
import { $loadTopbar } from "@/utils/cartevent.js";
export default {
  data() {
    return {
      topbarkey: 0,
    };
  },
  watch: {
    "$route.path": {
      handler(nerVal, oldVal) {
        if (oldVal != "/") {
          this.topbarkey++;
        }
      },
    },
  },
  computed: {
    ...mapState({
      isShowLoginModal: (state) => state.showModal.isShowLoginModal,
      isShowToast: (state) => state.showToast.isShowToast,
    }),
  },
  methods: {
    updateTopbarkeyFn() {
      //收到Details的刷新topbar的请求
      this.topbarkey++;
    },
  },
  mounted() {
    eventBus.$on("chengTapbarFn", () => {
      console.log(1111111111111);
      this.topbarkey++;
    });
    $loadTopbar.$on("eventLoadTopbar", () => {
      console.log(222222);
      this.topbarkey++;
    });
  },
  beforeDestroy() {
    eventBus.$off("chengTapbarFn");
    $loadTopbar.$off("chengTapbarFn");
  },
  components: {
    Footer,
    Header,
    Topbar,
    Login,
    Toast,
  },
  async created() {
    console.log("环境变量", process.env.VUE_APP_MY_NAME);
  },
};
</script>
<style lang="less">
/* 入场的起始状态 = 离场的结束状态 */
.slide-enter,
.slide-leave-to {
  opacity: 0;
}

.slide-enter-active,
.slide-leave-active {
  transition: opacity 0.3s linear;
}

.slide-enter-to,
.slide-leave {
  opacity: 1;
}
</style>
